package fxana;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateCell {
	private Date     TargetDate=null;
	static final String DATE_PATTERN ="yy/MM/dd";
	static final String FMT_DATE="%-8s";
	public DateCell(String date){
		try {
			SimpleDateFormat sdf=new SimpleDateFormat(DATE_PATTERN);
			TargetDate=sdf.parse(date);			
		}catch(ParseException e){
			System.out.print("Date is wrong:+ "+date);
		}
	}
	
	static public Date StringToDate(String date){
		Date result=null;
		try {
			SimpleDateFormat sdf=new SimpleDateFormat(DATE_PATTERN);
			result=sdf.parse(date);
		}catch(ParseException e ){
			return null;
		}catch(StringIndexOutOfBoundsException e){
			return null;
		}

		return result;
	}

	static public String DateToString(Date date){
		SimpleDateFormat sdf=new SimpleDateFormat(DATE_PATTERN);
		return String.format(FMT_DATE, sdf.format(date));
	}

	public Date GetRecDate(){
		return TargetDate;
	}	
	
	public String GetFSRecDate(){		
		SimpleDateFormat sdf=new SimpleDateFormat(DATE_PATTERN);
		return String.format(FMT_DATE, sdf.format(TargetDate));		
	}
	
	public static Integer DateDiff(Date d1,Date d2){
		long datetime1=d1.getTime();
		long datetime2=d2.getTime();
		long time_per_day=1000*60*60*24;
		return new Integer((int)((datetime1-datetime2)/time_per_day));
	}
}
